package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ap0stoL2
 * Date: 2023-07-23
 * Time: 22:30
 */
//runnable + 匿名内部类
public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        //创建匿名类实现runnable接口 重写run方法 实例化,传给Thread构造方法
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("i am thread");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t.start();

        while(true){
            System.out.println("i am main");
            Thread.sleep(5000);
        }
    }


}
